/**
 * 拥有Remote page功能的表格.
 *
 * @see SHED.grid.ListGrid
 * @author liuhz
 */
SHED.grid.PageGrid = Ext.extend(SHED.grid.ListGrid, {
    /**
     * @cfg {dwr} DWR call DWR方法
     *
     * <pre>
     * ---------------------------
     * call     page call              DWR PAGE方法
     * config   {filter, like, sort}   是否执行过滤
     * </pre>
     */
    /**
     * @cfg {id, data, total} pagemeta 与数据库Page对应的属性设置
     */
    pageSize: 20,
    // private
    initBbar: function() {
        if (this.bbar !== false) {
            this.bbar = new SHED.grid.PagingToolbar({
                store: this.ds,
                pageSize: this.pageSize
            });
        }
    },
    
    // private
    initDs: function() {
        if (!this.ds && this.recordHeaders) {
            this.ds = new Ext.data.Store({
                proxy: new SHED.data.DWRPageProxy(this.dwr.call, this.dwr.config, this),
                reader: new SHED.data.DWRPageReader(this.pagemeta, this.recordHeaders),
                remoteSort: true
            });
            delete this.recordHeaders;
        }
    },
    // overwrite
    onRender: function(ct, position) {
        this.filter = this.filter ? this.filter : {};
        this.like = this.like ? this.like : {};
        
        SHED.grid.PageGrid.superclass.onRender.call(this, ct, position);
        var bbar = this.getBottomToolbar();
        if (bbar.extendFun) {
            bbar.extendFun();
        }
    },
    
    /**
     * 刷新Grid,加载数据
     */
    reload: function() {
        var a = arguments ? arguments : {}, lo = this.store.lastOptions ? this.store.lastOptions : {}, pn = lo.params ? lo.params : {};
        a.params = Ext.applyIf(a.params ? a.params : {}, {
            start: 0,
            limit: pn.limit
        });
        this.store.reload(a);
    }
});
Ext.reg('pgrid', SHED.grid.PageGrid);
